home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
win
/
pascal
/
janus.exe
/
DIALOGWN.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-06-02
|
20KB
|
668 lines
Unit DialogWn;
{ Unit: DialogWn
Version: 1.07
Purpose: make a descendant of tWindow named tDialogWindow that behaves like
a modeless or modal dialog.
Features: - tDialogWindow descends from tWindow
- tDialogWindow and descendants may be used as MDI childs
- support for calculated resources is included e.g. a dialog
childs class & style may be changed on-the-fly (see GetChildClass)
tJanusDialogWindow object is an example for this: it decides at
runtime whether to uses BorDlg's or standard dialogs
- support DropDownBoxes just like a dialog (tWindow doesn't)
Date: 02/06/93
Developer: Peter Sawatzki (PS)
Buchenhof 3, D-5800 Hagen 1, Germany
CompuServe: 100031,3002
Date: Author:
04/22/92 PS initial release by PS
07/25/92 PS/jwp added Scroller support
08/01/92 PS added RunModal and modal support
08/12/92 PS removed SetClassName and NewClass, fixed bug in MDI support
08/14/92 PS fixed Focus problems in MDI, give focus to first ws_TabStop child
08/30/92 PS fixed more focus problems in MDI, added SysModal support
09/27/92 PS call DefDlgProc to support DropDownBoxes and Multiline edit controls
10/21/92 PS some changes for new OWL
01/28/93 PS add LoadMenu for automatic menu load
02/06/93 PS add support for InitResource,
fix BWCC's WM_NCCREATE glitch
Contributing: Jeroen W. Pluimers (jwp)
Copyright (c) 1992 Peter Sawatzki. All Rights Reserved.
}
Interface
Uses
WinTypes,
Win31,
{$IfDef Custom}
CustomWn,
{$EndIf}
Objects,
oWindows;
Type
tChildClass = Record
wX, wY, wCX, wCY: Integer;
wID: Word;
dwStyle: LongInt;
szClass: Array[0..63] Of Char;
szTitle: Array[0..131] Of Char;
CtlDataSize: Byte;
CtlData: Array[0..255] Of Byte;
End;
tDialogWindowAttr = Record
Name: pChar;
ItemCount: Integer;
MenuName,
ClassName,
FontName: pChar;
Font: hFont;
PointSize: Integer;
DlgItems: Pointer;
ResW,
ResH: Integer;
wUnitsX,
wUnitsY: Word
End;
{$IfDef Custom}
Ancestor = tCustomWindow;
{$Else}
Ancestor = tWindow;
{$EndIf}
pDialogWindow = ^tDialogWindow;
tDialogWindow = Object(Ancestor)
DialogAttr: tDialogWindowAttr;
ModalCode: pInteger;
Constructor Init (aParent: pWindowsObject; aName: pChar);
Destructor Done; Virtual;
Function Create: Boolean; Virtual;
Procedure Destroy; Virtual;
Procedure SetupWindow; Virtual;
Procedure GetWindowClass (Var aWndClass: tWndClass); Virtual;
Function GetWindowProc: tFarProc; Virtual;
Procedure DefWndProc (Var Msg: tMessage); Virtual;
Procedure DefDialogProc (Var Msg: tMessage); Virtual;
Procedure wmPaint(Var Msg: tMessage); Virtual wm_First+wm_Paint;
Function GetClassName: pChar; Virtual;
Procedure GetChildClass (Var aChildClass: tChildClass); Virtual;
Function CreateDialogChild (Var aChildClass: tChildClass): hWnd; Virtual;
Function CreateDialogChildren: Boolean; Virtual;
Procedure CreateDialogFont;
Procedure GetDialogInfo (aPtr: Pointer);
Procedure UpdateDialog; Virtual;
Function RunModal: Integer; Virtual;
Procedure EndDlg (aRetValue: Integer); Virtual;
Function GetItemHandle (DlgItemID: Integer): hWnd;
Function SendDlgItemMsg (DlgItemID: Integer; aMsg, wParam: Word; lParam: LongInt): LongInt;
Procedure Ok (Var Msg: tMessage); Virtual id_First+id_Ok;
Procedure Cancel (Var Msg: tMessage); Virtual id_First+id_Cancel;
Procedure wmClose (Var Msg: tMessage); Virtual wm_First+wm_Close;
Procedure wmSetFocus (Var Msg: tMessage); Virtual wm_First+wm_SetFocus;
Procedure wmSize (Var Msg: tMessage); Virtual wm_First+wm_Size;
Procedure wmLButtonDown (Var Msg: tMessage);Virtual wm_First+wm_LButtonDown;
End;
pJanusDialogWindow = ^tJanusDialogWindow;
tJanusDialogWindow = Object(tDialogWindow)
useBWCC: Boolean;
Constructor Init (aParent: pWindowsObject; aName: pChar; BorStyle: Boolean);
Function GetWindowProc: tFarProc; Virtual;
Procedure GetChildClass (Var aChildClass: tChildClass); Virtual;
End;
Function ExecDialogWindow (aDialogWindow: pDialogWindow): Integer;
Implementation
Uses
WinProcs,
Strings;
Const
sztDialogWindow = 'tDialogWindow';
ws_MdiChild = ws_Child Or ws_ClipSiblings Or ws_SysMenu Or ws_Caption Or
ws_ThickFrame Or ws_MinimizeBox Or ws_MaximizeBox Or ws_Visible;
ws_MdiAllowed = ws_MdiChild Or ws_Minimize Or ws_Maximize Or ws_ClipChildren Or
ws_Disabled Or ws_HScroll Or ws_VScroll;
BorDialog = 'BorDlg';
BorButton = 'BorBtn';
BorRadio = 'BorRadio';
BorCheck = 'BorCheck';
BorShade = 'BorShade';
BorStatic = 'BorStatic';
bss_Group = 1; {group box}
bss_Hdip = 2; {horizontal border}
bss_Vdip = 3; {hertical border}
bss_Hbump = 4; {horizontal speed bump}
bss_Vbump = 5; {vertical speed bump}
BWCCInst: tHandle = tHandle(0);
aBWCCDefMdiChildProc: tDefaultProc = Nil;
aBWCCDefWindowProc: tDefaultProc = Nil;
aBWCCDefDlgProc: tDefaultProc = Nil;
wm_EnterMenuLoop = $0211; {undocumented}
Function DlgToClientX (x, Units: Integer): Integer;
{DlgToClientX:= x*Units Div 4}
Inline($59/$58/ {Pop Cx Ax}
$F7/$E1/ {Mul Cx}
$D1/$E8/ {Shr Ax,1}
$D1/$E8); {Shr Ax,1}
Function DlgToClientY (y, Units: Integer): Integer;
{DlgToClientY:= y*Units Div 8}
Inline($59/$58/ {Pop Cx Ax}
$F7/$E1/ {Mul Cx}
$D1/$E8/ {Shr Ax,1}
$D1/$E8/ {Shr Ax,1}
$D1/$E8); {Shr Ax,1}
Constructor tDialogWindow.Init (aParent: pWindowsObject; aName: pChar);
Begin
Inherited Init(aParent,sztDialogWindow); {fake title}
FillChar(DialogAttr,SizeOf(DialogAttr),0);
ModalCode:= Nil; {assume modeless window}
With DialogAttr Do
If PtrRec(aName).Seg=0 Then Name:= aName Else Name:= StrNew(aName);
DefaultProc:= GetWindowProc
End;
Destructor tDialogWindow.Done;
Begin
With DialogAttr Do Begin
If PtrRec(Name).Seg<>0 Then StrDispose(Name);
If PtrRec(MenuName).Seg<>0 Then StrDispose(MenuName);
StrDispose(ClassName);
StrDispose(FontName)
End;
Inherited Done
End;
Function tDialogWindow.Create: Boolean;
Var
aResInfo, aRes: tHandle;
oStyle: LongInt;
Begin
Create:= False;
If (Status<>0) Or (DialogAttr.Name=Nil) Then
Exit;
aResInfo:= FindResource(hInstance, DialogAttr.Name, rt_Dialog);
If aResInfo<>0 Then
aRes:= LoadResource(hInstance, aResInfo);
If (aResInfo=0) Or (aRes=0) Then
Status:= em_InvalidWindow
Else Begin
If ModalCode<>Nil Then
If Parent=Nil Then Begin
Status:= em_InvalidWindow;
Exit
End Else Begin
EnableWindow(Parent^.hWindow,False); {disable Parent}
ModalCode^:= 0 {begin modal state}
End;
GetDialogInfo(LockResource(aRes));
If DialogAttr.MenuName<>Nil Then
Attr.Menu:= LoadMenu(hInstance, DialogAttr.MenuName);
CreateDialogFont;
UpdateDialog;
EnableKBHandler;
oStyle:= Attr.Style; Attr.Style:= Attr.Style And Not ws_Visible;
Create:= Inherited Create;
Attr.Style:= oStyle;
If Attr.Style And ws_Visible<>0 Then
ShowWindow(hWindow, sw_Show);
UnlockResource(aRes);
FreeResource(aRes)
End
End;
Procedure tDialogWindow.Destroy;
Begin
If (ModalCode<>Nil) And (Parent<>Nil) Then Begin
EnableWindow(Parent^.hWindow,True); {enable Parent}
If ModalCode^=0 Then {terminate modal window if not already terminated}
ModalCode^:= id_Cancel
End;
If DialogAttr.FontName<>Nil Then
DeleteObject(DialogAttr.Font);
Inherited Destroy
End;
Procedure tDialogWindow.SetupWindow;
Begin
Send